package com.dhwl.hsh.driver.ui.activity;

import android.graphics.Color;
import android.net.http.SslError;
import android.os.Bundle;
import android.view.KeyEvent;
import android.view.View;
import android.webkit.SslErrorHandler;
import android.webkit.WebChromeClient;
import android.webkit.WebView;
import android.webkit.WebViewClient;

import com.dhwl.hsh.driver.R;

import butterknife.Bind;

/**
 * webview 装载 html 页面
 *
 * @author Derek.Kidd
 * @time 2016/5/4 19:11
 */
public class WebViewActivity extends BaseActivity {

    @Bind(R.id.webView)
    WebView webView;

    public static final String WEBVIEW_URL = "webview_url";
    public static final String WEBVIEW_TITLE = "webview_title";

    private String url;

    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        if (getIntent().hasExtra(WEBVIEW_TITLE)) {
            setTitleContent(getIntent().getStringExtra(WEBVIEW_TITLE));
        } else {
            setTitleContent("详情");
        }
        url = getIntent().getStringExtra(WEBVIEW_URL);
    }

    @Override
    protected int getLayoutId() {
        return R.layout.activity_web_view;
    }

    @Override
    protected void initViews(Bundle savedInstanceState) {

        //设置webview自适应屏幕大小
        webView.getSettings().setUseWideViewPort(true);
        webView.getSettings().setLoadWithOverviewMode(true);
        webView.getSettings().setJavaScriptEnabled(true);
        webView.setBackgroundColor(Color.TRANSPARENT);
        //        webView.setInitialScale(98);
        webView.getSettings().setSupportZoom(true);
        webView.getSettings().setBuiltInZoomControls(true); //设置可以支持缩放

        webView.setWebViewClient(new WebViewClient()
        {
            //跳过HTTPS验证
            @Override
            public void onReceivedSslError(WebView view, SslErrorHandler handler, SslError error)
            {
                handler.proceed();
            }

        });

    }

    @Override
    protected void initData() {
        webView.loadUrl(url);
    }

}
